package com.kbs.im.common.udp.receiver;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;

/**
 * UDP 广播接收者服务启动器
 *
 * @author zhangzhang
 */
public class UdpReceiverBootStrap {

    public static final UdpReceiverBootStrap INSTANCE = new UdpReceiverBootStrap();

    private Bootstrap bootstrap = new Bootstrap();

    private NioEventLoopGroup workGroup = new NioEventLoopGroup();

    private final int PORT = 7777;

    private void run() {
        try {
            bootstrap.group(workGroup)
                    .channel(NioDatagramChannel.class)
                    .option(ChannelOption.SO_BROADCAST, true)
                    .handler(new UdpReceiverChannelInitializer());
            bootstrap.bind(PORT);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        UdpReceiverBootStrap.INSTANCE.run();
    }

}
